package org.example.controller;

import io.seata.core.context.RootContext;
import org.example.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

    private static Logger logger = LoggerFactory.getLogger(OrderController.class) ;

    @Autowired
    private OrderService orderService ;

    /**
     * 创建订单
     * @param userId
     * 用户 Id
     * @param commodityCode
     * 商品的编号
     * @param orderCount
     * 商品的数量
     * @return
     */
    @GetMapping("/create/{userId}/{commodityCode}/{orderCount}")
    public ResponseEntity<Void> create(@PathVariable("userId") String userId, @PathVariable("commodityCode") String commodityCode, @PathVariable("orderCount") int orderCount){
        logger.info("Order Service ... xid: " + RootContext.getXID());
        orderService.create(userId, commodityCode, orderCount) ;
        return ResponseEntity.ok().build() ;
    }
}
